package com.xrui.hbase.schema.impl;

import com.google.common.base.Objects;
import com.xrui.hbase.conversion.ProtobufCellConverter;
import com.xrui.hbase.schema.SchemaType;


public final class ProtobufCellSchema extends GenericCellSchema {
    private String protobufClassName;
    private String protobufFullName;

    private ProtobufCellSchema(String name, String value, String compression, String converter) {
        super(SchemaType.PROTOBUF, value, compression, converter);
        protobufFullName = name;
        protobufClassName = value;
    }

    public static ProtobufCellSchema create(String name, String value, String compression, String converter) {
        if(null == converter || converter.isEmpty()) {
            return new ProtobufCellSchema(name, value, compression, ProtobufCellConverter.PROVIDER_NAME);
        } else {
            return new ProtobufCellSchema(name, value, compression, converter);
        }
    }

    public static ProtobufCellSchema create(String name, String value, String compression) {
        return create(name, value, compression, null);
    }

    public static ProtobufCellSchema create(String name, String value) {
        return create(name, value, null, null);
    }

    @Override
    public String getValue() {
        return protobufClassName;
    }

    public String getProtobufClassName() {
        return protobufClassName;
    }

    public String getProtobufFullName() {
        return protobufFullName;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(ProtobufCellSchema.class)
            .add("type", mSchemaType)
            .add("name", protobufFullName)
            .add("protobuf", protobufClassName)
            .add("converter", mConverter)
            .add("compression", mCompressionProvider)
            .toString();
    }
}
